
import Vue from 'vue'
import Cookies from 'js-cookie'

import Element from 'element-ui'
import './assets/styles/element-variables.scss'

import '@/assets/styles/index.scss' // global css
import '@/assets/styles/enjoy.scss' // ruoyi css
import App from './App'
import store from './store'
import router from './router'
import directive from './directive' // directive
import plugins from './plugins' // plugins
import i18n from './lang'
import { download,otherDownload,postDownload } from '@/utils/request'
import Print from '@/plugins/print'
import dataV from '@jiaminghi/data-view'

//全屏组件使用
import fullscreen from 'vue-fullscreen'
Vue.use(fullscreen)
Vue.use(dataV)
Vue.use(Print)
import './assets/icons' // icon
import './permission' // permission control
import { getDicts } from "@/api/basic/dict/data";
import { getConfigKey } from "@/api/system/config";
import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree, formatValuesToText,format,isExcel, joinText, getFocusIdByProjectId, setProjectFocusId, getContentHeight, getColor, getIcon, removeChecked,deleteChecked, setProjectIfEdit, commitProjectIfEdit, editActived, handlePath,storeOrgPline, progressSort, getWatermarkInfo, getDate } from "@/utils/enjoy";
import { handlePasteNode } from '@/utils/paste'
// kityminder
import '@/libs/kityminder/kity.min'
import '@/libs/kityminder/kityminder.core.min'
import '@/libs/kityminder/hotbox'
import '@/libs/kityminder/kityminder.core.css'

// e-dropDown
import '@/components/e-dropdown/dropdown.css'

// VXE-TABLE
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
// 分页组件
import Pagination from "@/components/Pagination";
// 自定义表格工具组件
import RightToolbar from "@/components/RightToolbar"
// 富文本组件
import Editor from "@/components/Editor"
// 文件上传组件
import FileUpload from "@/components/FileUpload"
// 图片上传组件
import ImageUpload from "@/components/ImageUpload"
// 图片展示组件
import ImageShow from '@/components/ImageShow'
// 字典标签组件
import DictTag from '@/components/DictTag'
// 头部标签组件
import VueMeta from 'vue-meta'

import CountTo from 'vue-count-to'
// 字典数据组件
import DictData from '@/components/DictData'
//查询列表组件
import ListLayout from '@/layout/ListLayout'
//列表查询组件
import QueryForm from '@/layout/components/Global/GlobalQueryForm'
//dialog标题行
import DialogTit from '@/components/DialogTit'
//表格操作按钮
import TableBodyBtn from '@/components/TableBodyBtn'
// 脑图kityminder
import MinderTree from '@/components/MinderTree'
// 通用dropdown
import EDropdown from '@/components/e-dropdown'
import { constantRoutes } from '@/router'


// 脑图kityminder
import EMinder from '@/components/e-minder'
// Viewer 图片预览
import Viewer from 'v-viewer';
import 'viewerjs/dist/viewer.css';
Vue.use(Viewer);
Viewer.setDefaults({
    inline: false,
    button: true,
    navbar: false,
    title: false,
    toolbar: {
        prev: false, next: false, play: false, zoomIn: true, zoomOut: true, reset: true,rotateLeft: true, rotateRight: true, flipHorizontal: true, flipVertical: true
    },
    tooltip: true,
    movable: true,
    zoomable: true,
    rotatable: true,
    scalable: true,
    transition: true,
    fullscreen: true,
    keyboard: true,
    // url: "data-source"
});
// 默认配置
Element.Dialog.props.closeOnClickModal.default = false

// 全局方法挂载
Vue.prototype.storeOrgPline = storeOrgPline
Vue.prototype.progressSort = progressSort
Vue.prototype.getWatermarkInfo = getWatermarkInfo
Vue.prototype.getDate = getDate
Vue.prototype.getDicts = getDicts
Vue.prototype.getConfigKey = getConfigKey
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.selectDictLabels = selectDictLabels
Vue.prototype.download = download
Vue.prototype.otherDownload = otherDownload
Vue.prototype.postDownload = postDownload

Vue.prototype.handleTree = handleTree
Vue.prototype.format = format
Vue.prototype.isExcel = isExcel
Vue.prototype.formatValuesToText = formatValuesToText
Vue.prototype.joinText = joinText
Vue.prototype.getFocusIdByProjectId = getFocusIdByProjectId
Vue.prototype.setProjectFocusId = setProjectFocusId
Vue.prototype.getContentHeight = getContentHeight
Vue.prototype.getColor = getColor
Vue.prototype.getIcon = getIcon
Vue.prototype.removeChecked = removeChecked
Vue.prototype.deleteChecked = deleteChecked
Vue.prototype.setProjectIfEdit = setProjectIfEdit
Vue.prototype.commitProjectIfEdit = commitProjectIfEdit
Vue.prototype.editActived = editActived
Vue.prototype.handlePath = handlePath
Vue.prototype.handlePasteNode = handlePasteNode
Vue.prototype.getWatermarkInfo = getWatermarkInfo

// 全局组件挂载
Vue.component('DictTag', DictTag)
Vue.component('CountTo', CountTo)
Vue.component('Pagination', Pagination)
Vue.component('RightToolbar', RightToolbar)
Vue.component('Editor', Editor)
Vue.component('FileUpload', FileUpload)
Vue.component('ImageUpload', ImageUpload)
Vue.component('ImageShow', ImageShow)
Vue.component('MinderTree', MinderTree)
Vue.component('EDropdown', EDropdown)
Vue.component('ListLayout', ListLayout)
Vue.component('QueryForm', QueryForm)
Vue.component('DialogTit', DialogTit)
Vue.component('TableBodyBtn', TableBodyBtn)
Vue.component('EMinder', EMinder)
VXETable.setup({
  // 对组件内置的提示语进行国际化翻译
  i18n: (key, args) => i18n.t(key, args)
})
Vue.use(VXETable)
Vue.use(directive)
Vue.use(plugins)
Vue.use(VueMeta)
DictData.install()

/**
 * 国际化
 */
Vue.use(Element, {
  i18n: (key, value) => i18n.t(key, value)
})
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */

Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})

Vue.config.productionTip = false

// let router = null;
let instance = null;

function render(props = {}) {
  Vue.prototype.actions = props.actions
  const { container } = props;
  instance = new Vue({
    router,
    store,
    i18n,
    beforeCreate(){
      Vue.prototype.$bus = this
    },
    render: h => h(App),
  }).$mount(container ? container.querySelector('#ny-iqc') : '#ny-iqc');
}

if (window.__POWERED_BY_QIANKUN__) {
  // 使用qiankun, 将微应用的路径放到qiankun的全局变量下面，解决资源加载问题
  __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
} else {
  // 独立运行微应用, 不使用qiankun
  render();
}

export async function bootstrap() {
  console.log('[vue] vue app bootstraped');
}

export async function mount(props) {
  console.log('[vue] props from main framework', props);
  // props.setGlobalState({
  //   appRoutes: constantRoutes
  // });
  // props.onGlobalStateChange(state=>{
  //   store.dispatch('app/setLanguage', state.lang)
  // })
    render(props);

}

export async function unmount() {
  console.log('unmount')
  instance.$destroy();
  instance.$el.innerHTML = '';
  instance = null;
  // router = null;
}

